﻿using System;
using System.Data;
using System.Reflection;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using log4net;
namespace AnyOffice.general.system.unit
{
    public partial class index : ModulePage
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                DataTable table = new UnitDao().SelectAll(base.Conn);
                if (table.Rows.Count > 0)
                {
                    this.txtUnitName.Text = (table.Rows[0]["UnitName"] == DBNull.Value) ? "" : table.Rows[0]["UnitName"].ToString();
                    this.txtTelNo.Text = (table.Rows[0]["TelNo"] == DBNull.Value) ? "" : table.Rows[0]["TelNo"].ToString();
                    this.txtFaxNo.Text = (table.Rows[0]["FaxNo"] == DBNull.Value) ? "" : table.Rows[0]["FaxNo"].ToString();
                    this.txtPostNo.Text = (table.Rows[0]["PostNo"] == DBNull.Value) ? "" : table.Rows[0]["PostNo"].ToString();
                    this.txtAddress.Text = (table.Rows[0]["Address"] == DBNull.Value) ? "" : table.Rows[0]["Address"].ToString();
                    this.txtUrl.Text = (table.Rows[0]["Url"] == DBNull.Value) ? "" : table.Rows[0]["Url"].ToString();
                    this.txtEmail.Text = (table.Rows[0]["Email"] == DBNull.Value) ? "" : table.Rows[0]["Email"].ToString();
                    //this.txtBankName.Text = (table.Rows[0]["BankName"] == DBNull.Value) ? "" : table.Rows[0]["BankName"].ToString();
                    //this.txtBankNo.Text = (table.Rows[0]["BankNo"] == DBNull.Value) ? "" : table.Rows[0]["BankNo"].ToString();
                }
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                UnitDao dao2 = new UnitDao();
                UnitData data = new UnitData();
                if (this.txtUnitName.Text != string.Empty)
                {
                    data.UnitName = this.txtUnitName.Text;
                }
                if (this.txtTelNo.Text != string.Empty)
                {
                    data.TelNo = this.txtTelNo.Text;
                }
                if (this.txtFaxNo.Text != string.Empty)
                {
                    data.FaxNo = this.txtFaxNo.Text;
                }
                if (this.txtPostNo.Text != string.Empty)
                {
                    data.PostNo = this.txtPostNo.Text;
                }
                if (this.txtAddress.Text != string.Empty)
                {
                    data.Address = this.txtAddress.Text;
                }
                if (this.txtUrl.Text != string.Empty)
                {
                    data.Url = this.txtUrl.Text;
                }
                if (this.txtEmail.Text != string.Empty)
                {
                    data.Email = this.txtEmail.Text;
                }
                //if (this.txtBankName.Text != string.Empty)
                //{
                //    data.BankName = this.txtBankName.Text;
                //}
                data.BankName = string.Empty;
                //if (this.txtBankNo.Text != string.Empty)
                //{
                //    data.BankNo = this.txtBankNo.Text;
                //}

                data.BankNo = string.Empty;

                try
                {
                    dao2.Update(base.Conn, data);
                }
                catch (Exception exception)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("", exception);
                    }
                    this.lblMessage.Text = base.ShowPrompt("单位信息修改失败！");
                }
                this.lblMessage.Text = base.ShowPrompt("单位信息已修改！");
            }
        }
    }
}
